/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.system.domain;

import lombok.Data;
import cn.hutool.core.bean.BeanUtil;
import io.swagger.annotations.ApiModelProperty;
import cn.hutool.core.bean.copier.CopyOptions;
import javax.persistence.*;
import javax.persistence.CascadeType;
import javax.validation.constraints.*;
import javax.persistence.Entity;
import javax.persistence.Table;
import org.hibernate.annotations.*;
import java.sql.Timestamp;
import java.io.Serializable;
import java.util.List;
import java.util.Set;

/**
* @website https://el-admin.vip
* @description /
* @author whj
* @date 2021-01-16
**/
@Entity
@Data
@Table(name="task_mark")
public class TaskMark implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "mark_task_id")
    @ApiModelProperty(value = "id")
    private Integer markTaskId;

    @Column(name = "task_name")
    @ApiModelProperty(value = "任务名")
    private String taskName;

    @Column(name = "file_list")
    @ApiModelProperty(value = "分配到的文件路径")
    private String fileList;

    @Column(name = "num_image")
    @ApiModelProperty(value = "file_list中所含有的图片数量")
    private Long numImage;

    @ManyToMany
    @ApiModelProperty(value = "图片", hidden = true)
    @JoinTable(name = "task_image",
            joinColumns = {@JoinColumn(name = "mark_task_id",referencedColumnName = "mark_task_id")},
            inverseJoinColumns = {@JoinColumn(name = "image_id",referencedColumnName = "image_id")})
    private List<Image> images;

    @ManyToMany
    @JoinTable(name = "task_user",
            joinColumns = {@JoinColumn(name = "mark_task_id",referencedColumnName = "mark_task_id")},
            inverseJoinColumns = {@JoinColumn(name = "user_id",referencedColumnName = "user_id")})
    @ApiModelProperty(value = "所属用户")
    private List<User> users;

    @Column(name = "num_finish")
    @ApiModelProperty(value = "已完成的图片数量")
    private Long numFinish;

    @Column(name = "create_time")
    @CreationTimestamp
    @ApiModelProperty(value = "创建任务的时间")
    private Timestamp createTime;

    @Column(name = "finish_time")
    @ApiModelProperty(value = "完成时间")
    private Timestamp finishTime;

    @Column(name = "num_checked")
    @ApiModelProperty(value = "已审核通过的图片数量")
    private Long numChecked;

    @Column(name = "status")
    @ApiModelProperty(value = "0未完成/1完成部分/2等待审核/3审核通过/4审核不通过")
    private Long status;

    public void copy(TaskMark source){
        BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
    }
}